const path = require('path')
const fs = require('fs').promises

async function mergeJsonFiles() {
  const bossDir = path.join('.', 'boss')
  const jsonDir = path.join('.', 'json')
  const mergeFilePath = path.join(jsonDir, 'merge.json')
  const mergedData = []

  try {
      for (let i = 1; i <= 8; i++) {
          const filePath = path.join(bossDir, `${i}.json`)
          const fileData = await fs.readFile(filePath, 'utf8')
          const jsonData = JSON.parse(fileData)
          mergedData.push(...jsonData)
      }

      const strJson = JSON.stringify(mergedData, null, 2)
      await fs.writeFile(mergeFilePath, strJson, 'utf8')
      console.log('SUCESS merge.json')
  } catch (error) {
      console.error('发生错误:', error)
  }
}

mergeJsonFiles()
